# 图解算法练习4.4

# 找出二分查找算法的基线条件和递归条件


def binary_search(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = int((low + high) / 2)
        guess = list[mid]
        if guess == item:   #基线条件
            return mid
        if guess > item:    #递归条件
            high = mid - 1
        else:
            low = mid + 1
    return None


list = list(range(1, 11))
print(binary_search(list, 5))
